<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ include file="/public/header.jsp"%>
<html>
	<head>
		<title>厂家库产品录入管理</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$("#type_id").combotree({
				url:'<%=contextPath %>/springMVC/group/getSystemTypeTree?type=1',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					docSearch();
				}
			});
			$("#warehouse_id").combogrid({
				title:'选择仓库',
				panelWidth:550,
				panelHeight:400,
				url:'<%=contextPath %>/springMVC/warehouse/listPageWareHouse?type=4',
				idField:"id",
				textField:"name",
				rownumbers:true,
				nowrap:false,
				fitColumns:true,
				columns: [[
					{field:'id',hidden:true},
					{field:'type',hidden:true},
					{field:'dept_name',title:'所属部门',width:100,align:'center'},
					{field:'name',title:'仓库名称',width:100,align:'center'}
				]],
				pageSize:10,
				pageList:[10,50,100],  
				pagination:true,
				toolbar:'#tb',
				onChange:function(){
					doSearch2();
				}
			});
			$("#supplier_id").combogrid({
				idField:"id",
				textField:"company",
				title:'选择客户',
				url: '<%=contextPath %>/springMVC/crm/listPageSupplier',
			    panelWidth:550,
			    panelHeight:400,
			    rownumbers:true,
			    nowrap:false,
			    fitColumns:true,
			    columns: [[  
			       {field:'id',title:'主键',hidden:true},  
			       {title:'客户类别',field:'type_name',width:200,align:'center'},
				   {title:'公司名称',field:'company',width:200,align:'center'},
				   {title:'联系人',field:'contact',width:200,align:'center'},
				   {title:'TEL',field:'tel',width:200,align:'center'}
			    ]],
			    toolbar:'#ctb',
			    pageSize:10,
			    pageList : [10,50,100],  
				pagination:true,
				onChange:function(){
					doSearch2();
				}
			});
			
			$("#cSearchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 docSearch();
		       	} 
		   	}); 
			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		doSearch2();
		       	} 
		   	}); 
			$("#table").datagrid({
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/warehouse/listCustomerPageMaterial?flagType=1',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
				    {title:'主键',field:'id',hidden:true}
				]],
				columns:[[
					{title:'入库单号',field:'in_code',width:100,align:'center',sortable:true},
					{title:'入库时间',field:'operation_date',width:100,align:'center'},
					{title:'厂家名称',field:'supplier_name',width:100,align:'center'},
					{title:'仓库名称',field:'warehouse_name',width:100,align:'center'},
					{title:'申请人',field:'person_name',width:100,align:'center'},
					{title:'摘要',field:'remark',width:200,align:'center'},
					{title:'当前状态',field:'status',hidden:true},
					{title:'当前状态',field:'status_desc',width:100,align:'center'},
					{title:'操作',field:'edit',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						if(rowData.status == '<%=com.beaut.project.util.StaticData.NEW_CREATE%>'){
	                    	return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:addOrEditSupplierMaterial(1,'"+rowData.id+"');\"/>&nbsp;&nbsp;"
	                    		  +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-no' title='删除' onclick=\"javascript:deleteRows('"+rowData.id+"');\"/>&nbsp;&nbsp;"
	                    		  +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi(this,'"+rowData.id+"');\"/>";
						}
						if(rowData.status == '<%=com.beaut.project.util.StaticData.NO_PASS%>'){
							return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:addOrEditSupplierMaterial(1,'"+rowData.id+"');\"/>&nbsp;&nbsp;"
							      +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi(this,'"+rowData.id+"');\"/>";
						}
                    	return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='查看' onclick=\"javascript:addOrEditSupplierMaterial(2,'"+rowData.id+"');\"/>";
	
					}}
				]],
				view: detailview,
				detailFormatter:function(index,row){
					return '<div style="padding:2px"><table class="ddv"></table></div>';
				},
				onExpandRow: function(index,row){
					var c_s_id = row.id;
					var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv');
					 ddv.datagrid({
						title:'明细',
						url:'<%=contextPath %>/springMVC/warehouse/listCustomerMaterialDetail?c_s_id='+c_s_id,
						loadMsg:'正在加载数据，请稍后......',
						fitColumns:true,
						rownumbers:true,
						columns:[[
							{title:'产品编号',field:'code',width:150,align:'center'},
							{title:'产品名称',field:'name',width:300,align:'center'},
							{title:'规格/型号',field:'format_type',width:200,align:'center'},
							{title:'单位',field:'unit_name',width:100,align:'center'},
							{title:'申请数量',field:'num',width:100,align:'center'},
							{title:'备注',field:'remark',width:300,align:'center'}
						]],
					 	onResize:function(){
					        $('#table').datagrid('fixDetailRowHeight',index);
					    },
					 	onLoadSuccess:function(){
					       setTimeout(function(){
					         $('#table').datagrid('fixDetailRowHeight',index);
					       },0);
					   }
					 });
					 $('#table').datagrid('fixDetailRowHeight',index);
				},
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
		
		function shenpi(obj,id){
		      var flowBusinessUrl='<%=contextPath %>/springViews/warehouse/addOrEditSupplierMaterial.jsp?isShow=1&c_s_id='+id;
		      var param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.CP_SUPPLIER_IN_SHENPI%>")+"&businessId="+id;
		      $(obj).hide();
		      $.ajax({
							type:'POST',
							url:'<%=contextPath %>/springMVC/workFlow/toShenpi',
							dataType:"JSON",
							data:param,
							success:function(rtJson){
								if (rtJson.rtState == '0'){
									openDialogResize(rtJson.rtData.url,1000,800);
								}else{
									warningInfo(rtJson.rtMsrg);
								}
								$(obj).show();
							}
						});
		}
		function addOrEditSupplierMaterial(type,id){
			if(type==0){
				openDialogResize('<%=contextPath %>/springViews/warehouse/addOrEditSupplierMaterial.jsp?callback=rtCallBack',1000, 800);

			}else if(type==1){
				openDialogResize('<%=contextPath %>/springViews/warehouse/addOrEditSupplierMaterial.jsp?callback=rtCallBack&c_s_id='+id,1000, 800);
			}else{
				openDialogResize('<%=contextPath %>/springViews/warehouse/addOrEditSupplierMaterial.jsp?callback=rtCallBack&c_s_id='+id+'&isShow=1',1000, 800);
			}
		}
		function rtCallBack(){
			$('#table').datagrid('reload');
		}
		function deleteRows(id){
			var rows=$('#table').datagrid('getSelections');
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/warehouse/deleteCusMaterialDetail",
						data:"c_s_id="+id,
						dataType:"json",
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								warningInfo(rtJson.rtMsrg);
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function docSearch()
		{
			var cSearchValue = $('#cSearchValue').val();
			var type_id = $('#type_id').combotree('getValue');
			$('#supplier_id').combogrid('clear');
			$('#supplier_id').combogrid('grid').datagrid('load',{
				searchValue:cSearchValue,
				type_id:type_id
				});
		}
		
		function doSearch2()
		{
			var firstDay = $('#start_date').datebox('getValue');
			var endDay = $('#end_date').datebox('getValue');
			var supplier_id = $("#supplier_id").combogrid("getValue");
			var warehouse_id = $("#warehouse_id").combogrid("getValue");
			var searchValue = $("#searchValue").val();
			$('#table').datagrid('load',				
				{
					supplier_id:supplier_id,
					warehouse_id:warehouse_id,
					searchValue:searchValue,
					start_date:firstDay,
					end_date:endDay
					
				}
			);
		}
	</script>
	<body style="height: 97%">
		<div id="table" data-options="fit:true,toolbar:'#tb'" ></div>
		<div id="tb" style="padding:3px;height:auto">
			<div  style="float:left;">
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="addOrEditSupplierMaterial(0);">新增</a>
			</div>
			<div align="right">
			             开始日期: <input id="start_date" name="start_date" class="easyui-datebox"/>
				结束日期: <input id="end_date" name="end_date" class="easyui-datebox"/>
				选择厂家：<input  id="supplier_id" name="supplier_id" width="150px">
				选择仓库：<input  id="warehouse_id" name="warehouse_id" width="150px">
				其他查询：<input id="searchValue" name="searchValue" style="width:200px" title="入库单号/摘要关键字"  placeholder="入库单号/摘要关键字"/ >&nbsp;&nbsp;  			
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch2();"></a>
			</div>
		</div>
		<div id="ctb" style="padding:3px;height:auto;">
			<div align="right">
				分类：<input  id="type_id" name="type_id" >
				查询条件：<input id="cSearchValue" name="cSearchValue"  title="厂家名称或联系人" placeholder="厂家名称或联系人"/>
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="docSearch();"></a>
			</div>
		</div>
	</body>
</html>